function [restL,restR]=bdcorrector(index,n,term)

if(exist('funcbij.mat','file'))
    load funcbij;
end
if(exist('funchij.mat','file'))
    load funchij;
end
unimesh=(0:1/n:1)';
h=1/n;
switch term
    case 4
u0L=u0ex(unimesh(1));
u0R=u0ex(unimesh(n+1));
%u0L=0; u0R=1;

u1L=u1ex(unimesh(1));
u1R=u1ex(unimesh(n+1));
%u1L=0; u1R=0;

u2L=u2ex(unimesh(1));
u2R=u2ex(unimesh(n+1));
%u2L=0;u2R=0;

u3L=u3ex(unimesh(1));
u3R=u3ex(unimesh(n+1));
%u3L=0; u3R=0;

%the index-th equation
b001=bij{1}{index}(unimesh(2));
b00n=bij{1}{index}(unimesh(n));
h001=hij{1}{index}(unimesh(2));
h00n=hij{1}{index}(unimesh(n));

b101=bij{2}{index}(unimesh(2));
b10n=bij{2}{index}(unimesh(n));
h101=hij{2}{index}(unimesh(2));
h10n=hij{2}{index}(unimesh(n));

b201=bij{3}{index}(unimesh(2));
b20n=bij{3}{index}(unimesh(n));
h201=hij{3}{index}(unimesh(2));
h20n=hij{3}{index}(unimesh(n));

b301=bij{4}{index}(unimesh(2));
b30n=bij{4}{index}(unimesh(n));
h301=hij{4}{index}(unimesh(2));
h30n=hij{4}{index}(unimesh(n));

restL= -1/h/h*b001*u0L + 1/2/h*h001*u0L - 1/h/h*b101*u1L + 1/2/h*h101*u1L ...
         -1/h/h*b201*u2L + 1/2/h*h201*u2L - 1/h/h*b301*u3L + 1/2/h*h301*u3L;
restR= -1/h/h*b00n*u0R - 1/2/h*h00n*u0R - 1/h/h*b10n*u1R - 1/2/h*h10n*u1R ...
         -1/h/h*b20n*u2R - 1/2/h*h20n*u2R - 1/h/h*b30n*u3R - 1/2/h*h30n*u3R;
    case 3
     u0L=u0ex(unimesh(1));
u0R=u0ex(unimesh(n+1));

u1L=u1ex(unimesh(1));
u1R=u1ex(unimesh(n+1));

u2L=u2ex(unimesh(1));
u2R=u2ex(unimesh(n+1));


%the index-th equation
b001=bij{1}{index}(unimesh(2));
b00n=bij{1}{index}(unimesh(n));
h001=hij{1}{index}(unimesh(2));
h00n=hij{1}{index}(unimesh(n));

b101=bij{2}{index}(unimesh(2));
b10n=bij{2}{index}(unimesh(n));
h101=hij{2}{index}(unimesh(2));
h10n=hij{2}{index}(unimesh(n));

b201=bij{3}{index}(unimesh(2));
b20n=bij{3}{index}(unimesh(n));
h201=hij{3}{index}(unimesh(2));
h20n=hij{3}{index}(unimesh(n));


restL= -1/h/h*b001*u0L + 1/2/h*h001*u0L - 1/h/h*b101*u1L + 1/2/h*h101*u1L ...
         -1/h/h*b201*u2L + 1/2/h*h201*u2L ;
restR= -1/h/h*b00n*u0R - 1/2/h*h00n*u0R - 1/h/h*b10n*u1R - 1/2/h*h10n*u1R ...
         -1/h/h*b20n*u2R - 1/2/h*h20n*u2R ;
     
    case 2
             u0L=u0ex(unimesh(1));
u0R=u0ex(unimesh(n+1));

u1L=u1ex(unimesh(1));
u1R=u1ex(unimesh(n+1));



%the index-th equation
b001=bij{1}{index}(unimesh(2));
b00n=bij{1}{index}(unimesh(n));
h001=hij{1}{index}(unimesh(2));
h00n=hij{1}{index}(unimesh(n));

b101=bij{2}{index}(unimesh(2));
b10n=bij{2}{index}(unimesh(n));
h101=hij{2}{index}(unimesh(2));
h10n=hij{2}{index}(unimesh(n));



restL= -1/h/h*b001*u0L + 1/2/h*h001*u0L - 1/h/h*b101*u1L + 1/2/h*h101*u1L;
restR= -1/h/h*b00n*u0R - 1/2/h*h00n*u0R - 1/h/h*b10n*u1R - 1/2/h*h10n*u1R;

    case 1
                     u0L=u0ex(unimesh(1));
u0R=u0ex(unimesh(n+1));

%the index-th equation
b001=bij{1}{index}(unimesh(2));
b00n=bij{1}{index}(unimesh(n));
h001=hij{1}{index}(unimesh(2));
h00n=hij{1}{index}(unimesh(n));





restL= -1/h/h*b001*u0L + 1/2/h*h001*u0L ;
restR= -1/h/h*b00n*u0R - 1/2/h*h00n*u0R ;
        
end
     
     
     